#!/usr/bin/python

import os, sys, urllib
from ivic.vprocess.XmlParse import *

from ivic.core import Logging
logger = Logging.get_logger('ivic.vprocess.Software')
 
class SoftMetaInfo(object):
    
    def __init__(self, entity, wareroot):
        self.ent = entity
        self.name = entity.name
        self.exec_cmd = entity.exec_cmd
        self.path = '/'.join([wareroot, self.name])
        
        # how can we know the dirs a software has
        self.dirs = ['usr']
        
        #this is a bad idea to create the dir ???
        try:
            dirs = os.listdir('/usr')
            for each in dirs:
                try:
                    os.makedirs('/'.join([self.path, 'usr', each]), 0777)
                except Exception, e:
#                    logger.error('%s' % e)
                    pass
        except Exception, e:
            logger.error('%s' % e)
            raise
#    def soft_dirs(self):
#        pass
#    
#    def soft_path(self):
#        pass
#    
#    def soft_name(self):
#        pass
#    
#    def soft_exec(self):
#        pass


def retrieve(name, config):
    try:
        ent = main(name, config)
        software = SoftMetaInfo(ent, config.transfer.warehouse)
        return software
    except Exception, e:
        logger.error('%s' % e)
        raise
